# -*- coding: utf-8 -*-
# @Time    : 2020/6/20 下午1:13
# @Author  : caotian
# @FileName: lenetmodel.py
# @Software: PyCharm
import paddle
import paddle.fluid as fluid
import numpy as np
from paddle.fluid.dygraph.nn import Conv2D,Pool2D,Linear

class LeNet(fluid.dygraph.Layer):
    def __init__(self,num_classes=1):
        super(LeNet,self).__init__()
        self.conv1=Conv2D(num_channels=1,num_filters=6,filter_size=5,act='sigmoid')
        self.pool1=Pool2D(pool_size=2,pool_stride=2,pool_type='max')
        self.conv2=Conv2D(num_channels=6,num_filters=16,filter_size=5,act='sigmoid')
        self.pool2=Pool2D(pool_size=2,pool_stride=2,pool_type='max')
        self.conv3=Conv2D(num_channels=16,num_filters=120,filter_size=4,act='sigmoid')
        self.fc1=Linear(input_dim=120,output_dim=64,act='sigmoid')
        self.fc2=Linear(input_dim=64,output_dim=num_classes)
    def forward(self,x):
        x=self.conv1(x)
        x=self.pool1(x)
        x=self.conv2(x)
        x=self.pool2(x)
        x=self.conv3(x)
        x=fluid.layers.reshape(x,[x.shape[0],-1])
        x=self.fc1(x)
        x=self.fc2(x)
        return x